package com.eu.ebpm.engine.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class IdMaker {
	
	private static int num = 0;
	
	private static String time;
	
	public static synchronized long getId() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
		String timeValue = sdf.format(new Date());
		
		DecimalFormat df = new DecimalFormat("00");
		String value = df.format(getNum(timeValue));
		value += new Random().nextInt(10);
		value += new Random().nextInt(10);
		value += new Random().nextInt(10);
		value += new Random().nextInt(10);
		value += new Random().nextInt(10);
		time = timeValue;
		 return Long.valueOf(timeValue + value);
	}
	
	public synchronized static int getNum(String timeValue) {
		if(num == 99 || !timeValue.equals(time)) {
			num = 0;
			return num;
		}
		if(timeValue.equals(time)) {
			return ++ num;
		}
		return num;
	}
	
	public static void main(String[] args) {
		for(int i=0; i<105; i++) {
			System.out.println(IdMaker.getId());
		}
	}

}
